package cn.person.weichangjie.crawler.webmagic.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.scheduler.DuplicateRemovedScheduler;

/**
 * 定时任务模块
 * @author weichangjie
 */
@Service
public class ScheduledService extends DuplicateRemovedScheduler{

	@Autowired
	private PipelineService pipelineService;

	/**
	 * 简书
	 */
	@Scheduled(cron = "40 11 18 * * ? ") // 从0点开始,每2个小时执行一次
	public void jianShuScheduled() {
		System.out.println("----开始执行简书定时任务");
		Spider spider = Spider.create(new ProcessorService());
		spider.addUrl("https://github.com/code4craft");
		spider.addPipeline(pipelineService);
		spider.thread(5);
		spider.setExitWhenComplete(true);
		spider.start();
//		spider.stop();
	}

	@Override
	public Request poll(Task task) {
		// TODO Auto-generated method stub
		return null;
	}

}
